home *** CD-ROM | disk | FTP | other *** search
- Path: calvados.inria.fr!cluet
- From: Sophie.Cluet@inria.fr (Sophie Cluet)
- Newsgroups: comp.lang.c++
- Subject: storing address of member functions, HELP!
- Date: 17 Jan 1996 17:28:04 GMT
- Organization: INRIA
- Sender: cluet@calvados.inria.fr (Sophie Cluet)
- Distribution: world
- Message-ID: <4djbj4$5nu@news-rocq.inria.fr>
- NNTP-Posting-Host: calvados.inria.fr
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- Hello,
-
- I have a graph whose nodes represent operations and
- whose edges indicate the operations parameters.
- Each operation stores the address of its evaluation
- function which is invoked through a function called
- "evaluate" which simply evaluate the operation parameters
- and invoke the code.
-
- For instance, I have:
- Class nary_op
- {...
- op ** parameters; // the edges
- int parameters_nb;
- ...
- int evaluate(); // evaluate the parameters and invoke
- // the below stored function (code)
- int (nary_op::*code)(); // address of the evaluation function
- ...
- int build_list(); // one such evaluation fonction
- int and(); // another evaluation function
- ...}
-
- The classes are organised in a hierarchy.
- For instance,
- Class struct_op: public nary_op
- {char ** names; // added stored information
- ...
- int build_struct(); // an evaluation function
- // that uses the above names
- ...}
-
-
- Now, the problem. The compiler accepts neither of the following
- instructions on a nary_op:
-
- code=&struct_op::build_struct;
- or
- code=(int (nary_op::*)())&struct_op::build_struct;
-
- According to the C++ book I have, this assignment
- not beeing type-safe is forbidden. I aggree on the
- fact that it is not type safe, but I don't know of any
- casting that is.
-
- Do you have any idea to help me out?
-
- Of course, I do not want to duplicate "code" or the
- "int evaluate()" function. Also, I'd rather have as
- little late-binding as possible when evaluating my
- operations graph.
-
- Thanks in advance,
- Sophie.
-
-
-
-